﻿// JScript 文件
function setWidthHeight() {
    if (window.parent.frm.cols == "185,*") {
        window.parent.frm.cols = "0,*";
    }
    document.getElementById("menuContractList").style.width = document.body.offsetWidth * 0.99;
}
function setWidthcontractTB() {
    document.getElementById("contractTB2").style.width = document.getElementById("contractTB").style.width
}
//全选/全消
function selectAll() 
{
    var val = document.getElementById("chkSelectAll");
    var rowob = document.getElementsByTagName("input"); //.getElementsByName("contractRow");
    var rowcount=rowob.length;

    for (var i = 1; i < rowcount; i++) {
        rowob[i].checked = val.checked;
    }
}
function showDdl(strID1, strID2, strID3, strID4) {
    showHidden(strID1, strID2, strID3, strID4);
    document.getElementById(strID3).value = document.getElementById(strID1).value;
}

function showHidden(strID, strID1, strID2, strID3) {
    document.getElementById(strID).style.display = "none";
    document.getElementById(strID1).style.display = "none";
    document.getElementById(strID2).style.display = "";
    document.getElementById(strID3).style.display = "";
}

function MoreQueryOnload() {
    document.getElementById("imgOHName").style.display = "";
    document.getElementById("ddlOHName").style.display = "none";
    document.getElementById("txtOHName").style.display = "";
    document.getElementById("imgCEName").style.display = "";
    document.getElementById("ddlCEName").style.display = "none";
    document.getElementById("txtCEName").style.display = "";
    document.getElementById("imgSaleName").style.display = "";
    document.getElementById("ddlSaleName").style.display = "none";
    document.getElementById("txtSaleName").style.display = "";
}

  //文本框输入只能为非负数
  function txtIsNumber(txtID) {
      var a = document.getElementById(txtID).value;
      if (!(Math.abs(a) == a) || a == "") {
          alert("只能是非负数,也不能为空-Not less than zero！");
          document.getElementById(txtID).value = "0";
          document.getElementById(txtID).focus();
          return false;
      }
      else
      { return true; }
  }

  // 高级查询
  function show(strID,str,color) {
      document.getElementById(strID).style.display = str;
      if (str == "block") {
          DivShowAndHidden(strID);
          document.getElementById(strID).style.width = document.body.offsetWidth * 0.995;
      }
  }
  
  // 显示隐藏
  function hidden(strID) {
      document.getElementById(strID).style.display = "none";
  }

  //***** 查看Log ****/
  function showLog(strID, culomnType, contractNo, coCod) {
      //var p = $("#viewLogDiv");
      //var position = p.position();
      var ev = ev || window.event;
      var bb = mousePosition(ev)
      //window.alert(position.left + "----" + position.top + "----" + bb.x + bb.y);
      var obj = document.getElementById("viewLogDiv");
      obj.style.width = 100;
      obj.style.height = 100;
      obj.style.zIndex = 100000;
      obj.style.marginLeft = bb.x - 34;
      obj.style.marginTop = bb.y - 118;
      obj.style.display = "";
      $get("viewLogDiv").innerHTML = "<input id='viewlog' type=\"button\" onclick=\"ShowLog('"
      + culomnType + "','" + contractNo + "','" + coCod + "')\" onblur=\"hidden('viewLogDiv')\" value=\"ViewLog\" />";
      document.getElementById('viewlog').focus();
  }
  function mousePosition(ev) {
      if (ev.pageX || ev.pageY) {
          return { x: ev.pageX, y: ev.pageY };
      }
      return {
          x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
          y: ev.clientY + document.body.scrollTop - document.body.clientTop
      };
  }
  //document.onmousemove = mouseMove;
  function mouseMove(ev) {
      ev = ev || window.event;
      var mousePos = mousePosition(ev);
  }
  function ShowLog(culomnType, contactNo, coCode) {
      var ViewLog = ContractAddUpdateWebService;
      ViewLog.ShowLog(culomnType, contactNo, coCode, aShowLog);
      //alert(culomnType + '--' + contactNo + '--' + coCode);
  }
  function aShowLog(result) {
      var strID = "ShowLogDiv";
      var obj = document.getElementById(strID);
      $get(strID).innerHTML = result + "<div style='text-align:center;'><input type=\"button\" onclick=\"hidden('ShowLogDiv')\" value=\"Back\" /></div>";
      DivShowAndHidden(strID);
      document.getElementById(strID).style.width = document.body.offsetWidth * 0.995;
   }
  //***** 查看Log ****/

  //***** 删除合同 ****/
  function DeleteContract() {
      var val = document.getElementById("chkSelectAll");
      var rowob = document.getElementsByTagName("input");
      var rowcount = rowob.length;
      var str = "";

      for (var i = 1; i < rowcount; i++) {
          if (rowob[i].checked && rowob[i].id.indexOf("chk") != -1 && rowob[i].name != "contractRow") {
              str = str + rowob[i].name + "/";
          }
      }
      if (str.length > 1) {
          var ContractColumnAddUpdate = ContractAddUpdateWebService;
          ContractColumnAddUpdate.ContractDelete("/" + str, result);
      }
  }
  function result(n) {
      if (n > 0) {
          window.parent.mainFrame.location.reload();
      }
  }
  //***** 删除合同 ****/

  //***** 跳页控制 ****/
  function checkNumMax(flag) {
      if (flag) {
          var aa = document.getElementById('txtNewPageIndex').value;
          var bb = $get("lblPageCount").innerHTML.toString();
          var cc = Math.abs(bb);
          if ((cc < aa)) {
              document.getElementById('txtNewPageIndex').value = bb;
              window.alert("Not that Page！");
          }
      }
  }

  //***** 合同增删改 ****/
  function showHiddeTd1(str, tr, td) {
      // window.alert(str);
      var txt1 = document.getElementById("tr" + tr + "td" + td + "txt1");
      var txt2 = document.getElementById("tr" + tr + "td" + td + "txt2");
      txt2.value = txt1.value;
      txt1.style.display = "none";
      txt2.style.display = "block";
      txt2.focus();
  }
  function showHiddeTd2(str, tr, td, contractNoMain, columnID, coCode, userCode) {
      var txt1 = document.getElementById("tr" + tr + "td" + td + "txt1");
      var txt2 = document.getElementById("tr" + tr + "td" + td + "txt2");
      var temp = txt1.value;
      txt1.value = txt2.value;
      txt2.style.display = "none";
      txt1.style.display = "block";
      if (!(temp == txt1.value)) {
          updateORinsert(td, txt1.value, contractNoMain, columnID, coCode, userCode);
          //          document.getElementById("Ntr" + tr + "td" + td + "txt1").value = txt1.value;
//          document.getElementById(strID3).value = document.getElementById(strID1).value;
//          document.getElementById("Ntr" + tr + "td" + td + "txt2").value = txt1.value;
      }
  }
  function updateORinsert(columnPosition, columnValue, contractNoMain, columnID, coCode, userCode) {
      var ContractColumnAddUpdate = ContractAddUpdateWebService;
      ContractColumnAddUpdate.ContractColumnAddUpdate(coCode, userCode, columnPosition, columnValue, contractNoMain, columnID, aa);
  }
  function aa(result) {
      document.getElementById("refresh").value = result;
  }
  function showHiddeTd3(str, tr, td, contractNoMain, columnID, coCode, userCode) {
      var txt1 = document.getElementById("tr" + tr + "td" + td + "txt1");
      var txt2 = document.getElementById("tr" + tr + "td" + td + "txt2");
      var temp1 = txt1.value;
      var temp2 = txt2.value;
      if (temp1 != temp2) {
          txt2.value = temp2;
          txt2.style.display = "none";
          txt1.style.display = "block";
          updateORinsert(td, temp1, contractNoMain, columnID, coCode, userCode);
          //document.getElementById("refresh").value = 1;
      }
  }
  //***** 合同增删改 ****/

  //***** Repeat增删改 ****/
  function ShowAddRepeat(strID, columnPosition, contractNoMain, coCode, userCode, contractGroup) {
      var ContractColumnAddUpdate = ContractAddUpdateWebService;
      ContractColumnAddUpdate.ShowAddRepeat(columnPosition, contractNoMain, coCode, userCode, contractGroup, bb);
      tempShow("fieldsetShowAddRepeat", "block");
  }
  function bb(result) {
      $get("ShowAddRepeatDiv").innerHTML = result;
  }
  function tempShow(strID, str) {
      document.getElementById(strID).style.display = str;
      if (str == "block") {
          document.getElementById("ShowAddRepeatDiv").style.width = document.body.offsetWidth * 0.998;
          DivShowAndHidden(strID);
      }
      else {
          if (!(document.getElementById("refresh").value == 0)) {
              document.getElementById("refresh").value = 0;
              //window.parent.mainFrame.location.reload();
          }
      }
  }

  /**** 上传附件 ****/
  function ShowForFileUpload(path, uploadFlag, deleteFlag) {
      var bb = document.getElementsByName("uploadify");
      var newPath = "";
      var k = path.indexOf('/');
      newPath = path.substring(k + 1, path.length);
      //alert(newPath+'--'+path+'--'+ k);

      $(document).ready(function () {
          $("#uploadify").uploadify({
              'uploader': 'JS/jquery.uploadify-v2.1.4/uploadify.swf',
              'script': 'UploadHandler.ashx',
              'cancelImg': 'JS/jquery.uploadify-v2.1.4/cancel.png',
              'folder': newPath,
              'queueID': 'fileQueue',
              'auto': false,
              'multi': true
          }); ContractFileShow(path, deleteFlag);
      });
      document.getElementById("forContractFilePath").value = path;
      document.getElementById("forContractDeleteFlag").value = deleteFlag;
      ContractFileShow(path, deleteFlag);
      DivShowAndHidden("contractFileUpload");
      document.getElementById("contractFileUpload").style.width = document.body.offsetWidth * 0.995;
      document.getElementById("uploadify").value = "1";
      document.getElementById("filesUpload").style.display = uploadFlag > 0 ? "" : "none";
  }
  // Show Files
  function ContractFileShow(filePath, deleteFlag) {
      filePath = document.getElementById("forContractFilePath").value;
      deleteFlag = document.getElementById("forContractDeleteFlag").value;
      var temp = ContractAddUpdateWebService;
      temp.ContractFielsShow(filePath, deleteFlag, FilesShow);
  }
  function ContractFileDelete(filePath, deleteFlag) {
      var temp = ContractAddUpdateWebService;
      temp.ContractFileDelete(filePath, deleteFlag, FilesShow);
  }
  function FilesShow(result) {
      $get("filesDownLoadDiv").innerHTML = "";
      $get("filesDownLoadDiv").innerHTML = result;
  }

  /**** 上传附件 ****/

  function DivShowAndHidden(strID) {
      document.getElementById("ShowLogDiv").style.display = "none";
      document.getElementById("queryForMore").style.display = "none";
      document.getElementById("fieldsetShowAddRepeat").style.display = "none"; 
      document.getElementById("contractFileUpload").style.display = "none";
      document.getElementById("DataUpdateFromDiv").style.display = "none";

      var obj = document.getElementById(strID);
      obj.style.width = document.body.offsetWidth * 0.99;
      obj.style.zIndex = 1000;
      obj.style.backgroundColor = "#AABFD2"; //Gray
      obj.style.position = "absolute";
      obj.style.display = "";
  }


  function justShow(id) {
//      document.getElementById(id).style.display = "";
//      document.getElementById(id).style.visibility = "visible";
//      document.getElementById(id).focus();
  }

  function contractListName(strID1, strID2) {
      document.getElementById(strID1).value = document.getElementById(strID2).value;
  }
  function showHiddeTd12(tr, td) {
      // window.alert(str);
      var txt1 = document.getElementById("tr" + tr + "td" + td + "txt1");
      var txt2 = document.getElementById("tr" + tr + "td" + td + "txt2");

      txt1.style.display = "none";
      txt2.style.display = "block";
  }
  function showHiddeTd22(str, td, contractNoMain, columnID, coCode, userCode) {
      var temp = document.getElementById(str).value;
      updateORinsert(td, temp, contractNoMain, columnID, coCode, userCode);
  }

  function ContractSelected(strID1, strID2) {
      if (document.getElementById(strID1).checked) {
          document.getElementById(strID2).style.backgroundColor = "White";
      } else {
          document.getElementById(strID2).style.backgroundColor = "";
      }
  }